using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _3d
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Objeto3d modelo;
        Camera3D camera;
        Camera3D Camera2;
        Camera3D minimapa;

        public static Game1 Self;


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            Self = this;
        }

       


        protected override void LoadContent()
        {

            spriteBatch = new SpriteBatch(GraphicsDevice);

            modelo = new Objeto3d(Content.Load<Model>("cubo"));

            camera = new Camera3D();
            camera.position = new Vector3(0, 30, 30);
            Camera2 = new Camera3D();
            Camera2.position = new Vector3(30, 30, 30);
            minimapa = new Camera3D();
            minimapa.projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 5f);
            minimapa.LookAt = new Vector3(30, 30, 30);
            minimapa.position = new Vector3(0, 20, 20);
      

        }

        
        protected override void Update(GameTime gameTime)
        {

            camera.LookAt = modelo.posicao;
           
            if(Keyboard.GetState().IsKeyDown(Keys.D))
            {
                modelo.posicao.X += 0.1f;
                modelo.rotacao.Z += 15;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                modelo.posicao.X -= 0.1f;
                modelo.rotacao.Z -= 15;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                modelo.posicao.Z -= 0.1f;
                modelo.rotacao.X -= 15;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                modelo.posicao.Z += 0.1f;
                modelo.rotacao.X += 15;
            }
            

            base.Update(gameTime);
        }


        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            


            if (Keyboard.GetState().IsKeyDown(Keys.C))
            {
                modelo.Draw(Camera2);
            }

            else
            {
                modelo.Draw(camera);
            }

            modelo.Draw(minimapa);

            base.Draw(gameTime);
        }
    }
}
